/**
 * @file tooltip
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  PureComponent,
  PropTypes,
  Children
} from 'react';
import {
  Tooltip,
  OverlayTrigger
} from 'react-bootstrap';
import {getTooltipContainer} from '../util/helper';

export default class TooltipWrapper extends PureComponent {
  static defaultProps = {
    placement: 'top'
  };

  render() {
    const {
      tooltip, 
      children,
      id,
      placement
    } = this.props;

    if (!tooltip) {
      return Children.only(children);
    }

    const tooltipContent = (<Tooltip id={id}>{tooltip}</Tooltip>);

    return (
      <OverlayTrigger container={getTooltipContainer()} placement={placement} overlay={tooltipContent}>
        {children}
      </OverlayTrigger>
    );
  }
}
